home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-004 ms visual basic pro 30 / 4.imz / 4.IMA / TBLSTRU.FR_ / TBLSTRU.bin
Text File  |  1993-04-28  |  17KB  |  682 lines

  1. VERSION 2.00
  2. Begin Form fTblStru 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Table Structure"
  5.    ClientHeight    =   5550
  6.    ClientLeft      =   2100
  7.    ClientTop       =   1890
  8.    ClientWidth     =   5040
  9.    Height          =   5955
  10.    Left            =   2040
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   5550
  15.    ScaleWidth      =   5040
  16.    Top             =   1545
  17.    Width           =   5160
  18.    Begin TextBox cTableName 
  19.       BackColor       =   &H00FFFFFF&
  20.       Height          =   288
  21.       Left            =   1680
  22.       TabIndex        =   0
  23.       Tag             =   "OL"
  24.       Top             =   120
  25.       Width           =   1932
  26.    End
  27.    Begin PictureBox IndexBox 
  28.       BackColor       =   &H00C0C0C0&
  29.       BorderStyle     =   0  'None
  30.       Height          =   1692
  31.       Left            =   0
  32.       ScaleHeight     =   1695
  33.       ScaleWidth      =   5055
  34.       TabIndex        =   9
  35.       Top             =   3720
  36.       Width           =   5052
  37.       Begin CommandButton PrintButton 
  38.          Caption         =   "&Print Structure"
  39.          Height          =   372
  40.          Left            =   720
  41.          TabIndex        =   14
  42.          Top             =   1320
  43.          Visible         =   0   'False
  44.          Width           =   1452
  45.       End
  46.       Begin CommandButton AddTableButton 
  47.          Caption         =   "&Build the Table"
  48.          Enabled         =   0   'False
  49.          Height          =   372
  50.          Left            =   720
  51.          TabIndex        =   8
  52.          Top             =   1320
  53.          Visible         =   0   'False
  54.          Width           =   1452
  55.       End
  56.       Begin CommandButton CloseButton 
  57.          Cancel          =   -1  'True
  58.          Caption         =   "&Close"
  59.          Height          =   372
  60.          Left            =   2880
  61.          TabIndex        =   3
  62.          Top             =   1320
  63.          Width           =   1452
  64.       End
  65.       Begin CommandButton AddIndexButton 
  66.          Caption         =   "Add &Index"
  67.          Height          =   252
  68.          Left            =   1200
  69.          TabIndex        =   5
  70.          Top             =   120
  71.          Width           =   1332
  72.       End
  73.       Begin CommandButton DelIndexButton 
  74.          Caption         =   "&Delete Index"
  75.          Height          =   252
  76.          Left            =   2640
  77.          TabIndex        =   6
  78.          Top             =   120
  79.          Width           =   1332
  80.       End
  81.       Begin Grid cIndexes 
  82.          Cols            =   4
  83.          FixedCols       =   0
  84.          Height          =   750
  85.          Left            =   120
  86.          TabIndex        =   2
  87.          Top             =   420
  88.          Width           =   4815
  89.       End
  90.       Begin Line Line1 
  91.          BorderWidth     =   5
  92.          X1              =   0
  93.          X2              =   4800
  94.          Y1              =   0
  95.          Y2              =   0
  96.       End
  97.       Begin Label IndexesLabel 
  98.          BackColor       =   &H00C0C0C0&
  99.          Caption         =   "Indexes:"
  100.          Height          =   252
  101.          Left            =   240
  102.          TabIndex        =   10
  103.          Top             =   120
  104.          Width           =   1092
  105.       End
  106.    End
  107.    Begin PictureBox FieldBox 
  108.       BackColor       =   &H00C0C0C0&
  109.       BorderStyle     =   0  'None
  110.       Height          =   2892
  111.       Left            =   0
  112.       ScaleHeight     =   2895
  113.       ScaleWidth      =   5055
  114.       TabIndex        =   11
  115.       Top             =   600
  116.       Width           =   5052
  117.       Begin CommandButton RemoveFieldButton 
  118.          Caption         =   "&Remove Field"
  119.          Height          =   252
  120.          Left            =   2625
  121.          TabIndex        =   7
  122.          Top             =   0
  123.          Width           =   1332
  124.       End
  125.       Begin CommandButton AddFieldButton 
  126.          Caption         =   "&Add Field"
  127.          Height          =   252
  128.          Left            =   1200
  129.          TabIndex        =   4
  130.          Top             =   0
  131.          Width           =   1332
  132.       End
  133.       Begin Grid cFields 
  134.          BackColor       =   &H00FFFFFF&
  135.          Cols            =   3
  136.          FixedCols       =   0
  137.          Height          =   2532
  138.          Left            =   120
  139.          TabIndex        =   1
  140.          Top             =   288
  141.          Width           =   4800
  142.       End
  143.       Begin Label FieldsLabel 
  144.          BackColor       =   &H00C0C0C0&
  145.          Caption         =   "Fields:"
  146.          Height          =   192
  147.          Left            =   240
  148.          TabIndex        =   12
  149.          Top             =   0
  150.          Width           =   732
  151.       End
  152.    End
  153.    Begin Label TableNameLabel 
  154.       BackColor       =   &H00C0C0C0&
  155.       Caption         =   "Table Name:"
  156.       Height          =   252
  157.       Left            =   360
  158.       TabIndex        =   13
  159.       Top             =   120
  160.       Width           =   1212
  161.    End
  162. End
  163.  
  164. Option Explicit
  165.  
  166. Sub AddFieldButton_Click ()
  167.   MsgBar "Enter New Field Parameters, Press 'Close' when finished", False
  168.   fAddField.Show MODAL
  169.   MsgBar "", False
  170. End Sub
  171.  
  172. Sub AddIndexButton_Click ()
  173.   MsgBar "Enter New Index Parameters, Press 'Close' when finished", False
  174.   fIndexAdd.Show MODAL
  175.   MsgBar "", False
  176. End Sub
  177.  
  178. Sub AddTableButton_Click ()
  179.   Dim tbl As New TableDef
  180.   Dim fld As Field
  181.   Dim ind As Index
  182.   Dim i As Integer
  183.   Dim x As String
  184.  
  185.   On Error GoTo ATErr
  186.  
  187.   SetHourglass Me
  188.   MsgBar "Building New Table", True
  189.  
  190.   tbl.Name = cTableName
  191.  
  192.   'search to see if table exists
  193.   For i = 0 To gCurrentDB.TableDefs.Count - 1
  194.     If UCase(gCurrentDB.TableDefs(i).Name) = UCase(tbl.Name) Then
  195.       If MsgBox(tbl.Name + " already exists, delete it?", 4) = YES Then
  196.          gCurrentDB.TableDefs.Delete gCurrentDB.TableDefs(tbl.Name)
  197.       Else
  198.          ResetMouse Me
  199.          Exit Sub
  200.       End If
  201.       Exit For
  202.     End If
  203.   Next
  204.  
  205.   'add the first field
  206.   cFields.Row = 1
  207.   cFields.Col = 0
  208.   If cFields = "" Then
  209.     Beep
  210.     MsgBox "No Fields Defined!", 48
  211.     Exit Sub
  212.   End If
  213.   Set fld = New Field
  214.   fld.Name = cFields
  215.   cFields.Col = 1
  216.   fld.Type = GetFieldType((cFields))
  217.   If cFields = "Counter" Then
  218.     fld.Attributes = &H10   'counter type
  219.   End If
  220.   cFields.Col = 2
  221.   fld.Size = Val(cFields)
  222.   tbl.Fields.Append fld
  223.  
  224.   gCurrentDB.TableDefs.Append tbl
  225.  
  226.   'add the rest of the fields
  227.   For i = 2 To cFields.Rows - 1
  228.     Set fld = New Field
  229.     cFields.Row = i
  230.     cFields.Col = 0
  231.     fld.Name = cFields
  232.     cFields.Col = 1
  233.     fld.Type = GetFieldType((cFields))
  234.     If cFields = "Counter" Then
  235.       fld.Attributes = &H10   'counter type
  236.     End If
  237.     cFields.Col = 2
  238.     fld.Size = Val(cFields)
  239.     gCurrentDB.TableDefs(tbl.Name).Fields.Append fld
  240.   Next
  241.  
  242.   'add the indexes
  243.   For i = 1 To cIndexes.Rows - 1
  244.     Set ind = New Index
  245.     cIndexes.Row = i
  246.     cIndexes.Col = 0
  247.     If cIndexes = "" Then Exit For
  248.     ind.Name = cIndexes
  249.     cIndexes.Col = 1
  250.     ind.Fields = cIndexes
  251.     cIndexes.Col = 2
  252.     If cIndexes = "True" Then
  253.       ind.Unique = True
  254.     Else
  255.       ind.Unique = False
  256.     End If
  257.     cIndexes.Col = 3
  258.     If gstDataType = "ODBC" Then
  259.       cIndexes = "N/A"
  260.     Else
  261.       If cIndexes = "True" Then
  262.         ind.Primary = True
  263.       Else
  264.         ind.Primary = False
  265.       End If
  266.     End If
  267.     gCurrentDB.TableDefs(tbl.Name).Indexes.Append ind
  268.   Next
  269.  
  270.   RefreshTables fTables.cTableList, True
  271.  
  272.   GoTo ATEnd
  273.  
  274. ATErr:
  275.   ResetMouse Me
  276.   ShowError
  277.   Resume ATEnd
  278.  
  279. ATEnd:
  280.   ResetMouse Me
  281.   MsgBar "", False
  282.   Unload Me
  283.  
  284. End Sub
  285.  
  286. Sub cFields_DblClick ()
  287.    Dim f As New fDataBox
  288.    Dim erm As String
  289.  
  290.    'only allowed on existing tables
  291.    If gfAddTableFlag = True Then
  292.      Exit Sub
  293.    End If
  294.  
  295.    On Error GoTo FldPropErr
  296.    cFields.Row = cFields.SelStartRow
  297.    cFields.Col = 0
  298.  
  299.    Set gCurrentField = gCurrentDB.TableDefs(fTables.cTableList).Fields(cFields)
  300.    f.Caption = "Field Properties"
  301.    f.Tag = "FLD"
  302.  
  303.    erm = "Name"
  304.    f.cData.AddItem "Name = " + gCurrentField.Name
  305.    erm = "Type"
  306.    f.cData.AddItem "Type = " & gCurrentField.Type
  307.    erm = "Size"
  308.    f.cData.AddItem "Size = " & gCurrentField.Size
  309.    erm = "SourceField"
  310.    f.cData.AddItem "SourceField = " + gCurrentField.SourceField
  311.    erm = "SourceTable"
  312.    f.cData.AddItem "SourceTable = " + gCurrentField.SourceTable
  313.    erm = "CollatingOrder"
  314.    f.cData.AddItem "CollatingOrder = " & gCurrentField.CollatingOrder
  315.    erm = "Attributes"
  316.    f.cData.AddItem "Attributes = &H" & Hex(gCurrentField.Attributes)
  317.    erm = "OrdinalPosition"
  318.    f.cData.AddItem "OrdinalPosition = " & gCurrentField.OrdinalPosition
  319.  
  320.    f.Show MODAL
  321.  
  322.   GoTo FldPropEnd
  323.  
  324. FldPropErr:
  325.   f.cData.AddItem erm + ":" + Error$
  326.   Resume Next
  327.  
  328. FldPropEnd:
  329.  
  330. End Sub
  331.  
  332. Sub cIndexes_DblClick ()
  333.    Dim f As New fDataBox
  334.    Dim erm As String
  335.  
  336.    'only allowed on existing tables
  337.    If gfAddTableFlag = True Then
  338.      Exit Sub
  339.    End If
  340.  
  341.    On Error GoTo IndPropErr
  342.    cIndexes.Row = cIndexes.SelStartRow
  343.    cIndexes.Col = 0
  344.  
  345.    Set gCurrentIndex = gCurrentDB.TableDefs(fTables.cTableList).Indexes(cIndexes)
  346.    f.Caption = "Field Properties"
  347.    f.Tag = "IND"
  348.  
  349.    erm = "Name"
  350.    f.cData.AddItem "Name = " + gCurrentIndex.Name
  351.    erm = "Fields"
  352.    f.cData.AddItem "Fields = " + gCurrentIndex.Fields
  353.    erm = "Unique"
  354.    f.cData.AddItem "Unique Flag = " + stTrueFalse((gCurrentIndex.Unique))
  355.    erm = "Primary"
  356.    f.cData.AddItem "PrimaryFlag = " + stTrueFalse((gCurrentIndex.Primary))
  357.  
  358.    f.Show MODAL
  359.  
  360.   GoTo IndPropEnd
  361.  
  362. IndPropErr:
  363.   f.cData.AddItem erm + ":" + Error$
  364.   Resume Next
  365.  
  366. IndPropEnd:
  367.  
  368. End Sub
  369.  
  370. Sub CloseButton_Click ()
  371.   Unload Me
  372.   MsgBar "", False
  373. End Sub
  374.  
  375. Sub cTableName_Change ()
  376.   If cTableName = "" Then
  377.     AddTableButton.Enabled = False
  378.   Else
  379.     AddTableButton.Enabled = True
  380.   End If
  381. End Sub
  382.  
  383. Sub cTableName_KeyPress (KeyAscii As Integer)
  384.   If cTableName.TabStop = False Then
  385.     KeyAscii = 0   'throw away the key
  386.   End If
  387. End Sub
  388.  
  389. Sub DelIndexButton_Click ()
  390.   cIndexes.Row = cIndexes.SelStartRow
  391.   cIndexes.Col = 0
  392.  
  393.   If cIndexes = "" Then Exit Sub
  394.  
  395.   If MsgBox("Delete """ + cIndexes + """ index?", MSGBOX_TYPE) = YES Then
  396.     If gfAddTableFlag = False Then
  397.       gCurrentDB.TableDefs(fTables.cTableList).Indexes.Delete gCurrentDB.TableDefs(fTables.cTableList).Indexes(cIndexes)
  398.     End If
  399.     'refresh the list of indexes
  400.     If cIndexes.Rows = 2 Then
  401.       cIndexes.Col = 0
  402.       cIndexes = ""
  403.       cIndexes.Col = 1
  404.       cIndexes = ""
  405.       cIndexes.Col = 2
  406.       cIndexes = ""
  407.     Else
  408.       cIndexes.RemoveItem cIndexes.Row
  409.     End If
  410.   End If
  411.  
  412. End Sub
  413.  
  414. Sub Form_Load ()
  415.   Dim tbl As TableDef
  416.   Dim i As Integer
  417.   Dim s As String
  418.   On Error GoTo LoadErr
  419.   
  420.   Width = 5160
  421.   Height = 5955
  422.   SetHourglass Me
  423.   fTables.MousePointer = HOURGLASS
  424.   MsgBar "Opening Design Form", True
  425.   fTblStru.cTableName.TabStop = gfAddTableFlag
  426.   'setup field grid titles
  427.   cFields.ColWidth(0) = 2500
  428.   cFields.ColWidth(1) = 1500
  429.   cFields.ColWidth(2) = 500
  430.   cFields.Row = 0
  431.   cFields.Col = 0
  432.   cFields = "Name"
  433.   cFields.Col = 1
  434.   cFields = "Type"
  435.   cFields.Col = 2
  436.   cFields = "Size"
  437.   'setup index grid titles
  438.   cIndexes.ColWidth(0) = 850
  439.   cIndexes.ColWidth(1) = 2250
  440.   cIndexes.ColWidth(2) = 650
  441.   cIndexes.ColWidth(3) = 700
  442.   cIndexes.Row = 0
  443.   cIndexes.Col = 0
  444.   cIndexes = "Name"
  445.   cIndexes.Col = 1
  446.   cIndexes = "Indexed Fields"
  447.   cIndexes.Col = 2
  448.   cIndexes = "Unique"
  449.   cIndexes.Col = 3
  450.   cIndexes = "Primary"
  451.  
  452.   If gfAddTableFlag = True Then
  453.     Caption = "Add Table"
  454.     AddTableButton.Visible = True
  455.     cFields.Rows = 2
  456.     cIndexes.Rows = 2
  457.   Else
  458.     Caption = "View/Modify Structure"
  459.     PrintButton.Visible = True
  460.     RemoveFieldButton.Visible = False
  461.     fTblStru.cTableName = fTables.cTableList
  462.     Set tbl = gCurrentDB.TableDefs(fTables.cTableList)
  463.  
  464.     cFields.Rows = tbl.Fields.Count + 1
  465.     For i = 1 To cFields.Rows - 1
  466.       cFields.Row = i
  467.       cFields.Col = 0
  468.       cFields = tbl.Fields(i - 1).Name
  469.       cFields.Col = 1
  470.       Select Case tbl.Fields(i - 1).Type
  471.         Case FT_TRUEFALSE
  472.           s = "True/False"
  473.         Case FT_BYTE
  474.           s = "Byte"
  475.         Case FT_INTEGER
  476.           s = "Integer"
  477.         Case FT_LONG
  478.           If tbl.Fields(i - 1).Attributes And &H10 = &H10 Then
  479.             s = "Counter"
  480.           Else
  481.             s = "Long"
  482.           End If
  483.         Case FT_CURRENCY
  484.           s = "Currency"
  485.         Case FT_SINGLE
  486.           s = "Single"
  487.         Case FT_DOUBLE
  488.           s = "Double"
  489.         Case FT_DATETIME
  490.           s = "Date/Time"
  491.         Case 9
  492.           s = "Reserved/9"
  493.         Case FT_STRING
  494.           s = "String"
  495.         Case FT_BINARY
  496.           s = "Binary"
  497.         Case FT_MEMO
  498.           s = "Memo"
  499.         Case Else
  500.           s = CStr(tbl.Fields(i - 1).Type)
  501.       End Select
  502.       cFields = s
  503.       cFields.Col = 2
  504.       cFields = CStr(tbl.Fields(i - 1).Size)
  505.     Next
  506.  
  507.     If tbl.Indexes.Count = 0 Then
  508.       cIndexes.Rows = 2
  509.     Else
  510.       cIndexes.Rows = tbl.Indexes.Count + 1
  511.       For i = 1 To cIndexes.Rows - 1
  512.         cIndexes.Row = i
  513.         cIndexes.Col = 0
  514.         cIndexes = tbl.Indexes(i - 1).Name
  515.         cIndexes.Col = 1
  516.         cIndexes = tbl.Indexes(i - 1).Fields
  517.         cIndexes.Col = 2
  518.         If tbl.Indexes(i - 1).Unique = False Then
  519.           s = "False"
  520.         Else
  521.           s = "True"
  522.         End If
  523.         cIndexes = s
  524.         cIndexes.Col = 3
  525.         If gstDataType = "ODBC" Then
  526.           s = "N/A"
  527.         Else
  528.           If tbl.Indexes(i - 1).Primary = False Then
  529.             s = "False"
  530.           Else
  531.             s = "True"
  532.           End If
  533.         End If
  534.         cIndexes = s
  535.       Next
  536.     End If
  537.   End If
  538.  
  539.   'lock the titles row and set the selected cell
  540.   cFields.Row = 1
  541.   cFields.SelStartCol = 0
  542.   cFields.SelEndCol = 0
  543.   cFields.FixedRows = 1
  544.   cIndexes.Row = 1
  545.   cIndexes.SelStartCol = 0
  546.   cIndexes.SelEndCol = 0
  547.   cIndexes.FixedRows = 1
  548.  
  549.   ResizeFieldGrid
  550.  
  551.   GoTo LoadEnd
  552.  
  553. LoadErr:
  554.   ResetMouse Me
  555.   fTables.MousePointer = DEFAULT_MOUSE
  556.   ShowError
  557.   Unload Me
  558.   MsgBar "", False
  559.   Exit Sub
  560.   Resume LoadEnd
  561.  
  562. LoadEnd:
  563.   ResetMouse Me
  564.   fTables.MousePointer = DEFAULT_MOUSE
  565.   MsgBar "", False
  566.         
  567. End Sub
  568.  
  569. Sub Form_Paint ()
  570.   Outlines Me
  571.   FieldBox.Refresh
  572.   PicOutlines FieldBox, cFields
  573.   IndexBox.Refresh
  574.   PicOutlines IndexBox, cIndexes
  575. End Sub
  576.  
  577. Sub Form_Resize ()
  578.   On Error Resume Next
  579.  
  580.   If WindowState <> 1 Then
  581.     If Width < 5190 Then
  582.       Width = 5190
  583.     End If
  584.     FieldBox.Width = Width' - 350
  585.     cFields.Width = FieldBox.Width - 350
  586.     IndexBox.Width = Width' - 350
  587.     cIndexes.Width = IndexBox.Width - 350
  588.     Line1.X2 = IndexBox.Width
  589.     Form_Paint
  590.   End If
  591. End Sub
  592.  
  593. Sub PrintButton_Click ()
  594.   'this routine simply prints the currently
  595.   'selected table's definition
  596.  
  597.   Dim i As Integer
  598.   Dim s As String
  599.  
  600.   MsgBar "Printing Table Structure", True
  601.   Printer.Print
  602.   Printer.Print
  603.   Printer.Print
  604.   Printer.Print "DataBase: " + gstDBName
  605.   Printer.Print
  606.   Printer.Print
  607.   Printer.Print "Table Definition for " + cTableName
  608.   Printer.Print
  609.   Printer.Print
  610.   Printer.Print "Fields: (Name - Type - Size)"
  611.   Printer.Print String(60, "-")
  612.   For i = 1 To cFields.Rows - 1
  613.     cFields.Row = i
  614.     cFields.Col = 0
  615.     s = cFields + " - "
  616.     cFields.Col = 1
  617.     s = s + cFields + " - "
  618.     cFields.Col = 2
  619.     s = s + cFields
  620.     Printer.Print s
  621.   Next
  622.   Printer.Print
  623.   Printer.Print
  624.   Printer.Print "Index List (Name - Fields - Unique)"
  625.   Printer.Print String(60, "-")
  626.   For i = 1 To cIndexes.Rows - 1
  627.     cIndexes.Row = i
  628.     cIndexes.Col = 0
  629.     s = cIndexes + " - "
  630.     cIndexes.Col = 1
  631.     s = s + cIndexes + " - "
  632.     cIndexes.Col = 2
  633.     s = s + cIndexes
  634.     Printer.Print s
  635.   Next
  636.   Printer.NewPage
  637.   Printer.EndDoc
  638.   MsgBar "", False
  639. End Sub
  640.  
  641. Sub RemoveFieldButton_Click ()
  642.   On Error GoTo RFErr
  643.  
  644.   cFields.Row = cFields.SelStartRow
  645.   cFields.Col = 0
  646.  
  647.   If cFields = "" Then Exit Sub
  648.  
  649.   If MsgBox("Remove """ + cFields + """ field?", MSGBOX_TYPE) = YES Then
  650.     'refresh the list of indexes
  651.     If cFields.Rows = 2 Then
  652.       cFields.Col = 0
  653.       cFields = ""
  654.       cFields.Col = 1
  655.       cFields = ""
  656.       cFields.Col = 2
  657.       cFields = ""
  658.     Else
  659.       cFields.RemoveItem cFields.Row
  660.       ResizeFieldGrid
  661.     End If
  662.   End If
  663.   GoTo RFEnd
  664.  
  665. RFErr:
  666.   ShowError
  667.   Resume RFEnd
  668.  
  669. RFEnd:
  670.  
  671. End Sub
  672.  
  673. Sub ResizeFieldGrid ()
  674.   If cFields.Rows < 12 Then
  675.     cFields.Height = cFields.Rows * 245
  676.     FieldBox.Height = cFields.Height + 360
  677.     IndexBox.Top = FieldBox.Top + FieldBox.Height + 250
  678.     Height = IndexBox.Top + IndexBox.Height + 500
  679.   End If
  680. End Sub
  681.  
  682.